#ifndef _SERVER_H_
#define _SERVER_H_
#include "../socket.h"
#include "../networkchat.h"
#include <pthread.h>
#include <map>
#include <list>
#include <utility>
#include <vector>

using namespace std;

typedef struct
{
	pthread_t reader;
	pthread_t writer;
} Threads;

// Clasa ce contine toata logica partii de server
class Server {
public:
	void start();
	void stop();
	void monitorSocket(int clientSocket);
	Server(int portNumber, const char *usersFileName);
	~Server();
	
	list<char*> msg;
	pthread_mutex_t mutex;
	pthread_cond_t semnal;
	bool work, local_work[1000];

private:
	int validateUser(const char *username, const char *password);
	void sendBroadcast(char *message);
	
	Socket m_socket;
	int m_portNumber;
	char *m_usersFileName;
	map<int,Threads> ht; //o tabela globala cu conexiuni(socket-uri) deschise si threadurile asociate
};

#endif
